package code;

import java.util.ArrayList;

import main.ErrorException;
import define.ReferenceHead;
import excelBase.Sheet;

public class ReferenceClass 
{
	private ArrayList<ReferenceMember> m_members;
	private Sheet m_sheet;
	
	public ReferenceClass(Sheet sheet) throws ErrorException
	{
		m_sheet = sheet;
		makeMember();
	}
	
	private void makeMember() throws ErrorException
	{
		String[][] texts = new String[ReferenceHead.values().length][];
		for(ReferenceHead rh: ReferenceHead.values())
		{
			texts[rh.ordinal()] = m_sheet.getCodeText(rh.getName());
		}
		m_members = new ArrayList<>();
		for(int i = 0; i < texts[0].length; ++i)
		{
			String name = texts[ReferenceHead.E_NAME_RH.ordinal()][i];
			String type = texts[ReferenceHead.E_TYPE_RH.ordinal()][i];
			m_members.add(new ReferenceMember(this, name, type, texts[ReferenceHead.E_DEFAULT_RH.ordinal()][i], 
					texts[ReferenceHead.E_COMMENT_RH.ordinal()][i]));
		}
		if(m_members.size() == 0)
		{
			m_members = null;
		}
	}
	
	public ArrayList<ReferenceMember> getMemberList()
	{
		return m_members;
	}
	
	public String getName()
	{
		return m_sheet.getName();
	}
}
